package models

import (
	"context"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo/options"
	l "hospital-srv/basic/inits"
	"time"
)

type Collect struct {
	Id                          uint32    `bson:"id"`
	Xid                         string    `bson:"Xid"` //清理查询id
	UserId                      int32     `bson:"user_id"`
	TempValue                   float32   `bson:"temp_value"`
	BloodSugarValue             float32   `bson:"blood_sugar_value"`
	SystolicBloodPressureValue  float32   `bson:"systolic_blood_pressure_value"`
	DiastolicBloodPressureValue float32   `bson:"diastolic_blood_pressure_value"`
	BloodOxygenValue            float32   `bson:"blood_oxygen_value"`
	DeviceID                    int64     `bson:"device_id"`
	CreatedAt                   time.Time `bson:"createdAt"`
}

func (c *Collect) Create() error {
	_, err := l.Mongo.InsertOne(context.Background(), &c, &options.InsertOneOptions{})
	return err
}
func (c *Collect) GetCollectRetail() error {
	id, err := primitive.ObjectIDFromHex(c.Xid)
	if err != nil {
		return err // ID 格式错误
	}
	filter := bson.M{"_id": id}
	err = l.Mongo.FindOne(context.Background(), filter).Decode(&c)
	return err
}
